/**
 @author : MAMAMA
 @date: 2020-03-24
*/

#ifndef _STREAM_H_
#define _STREAM_H_

#include "stm32f10x.h"
#include "Stream_ll.h"
#include "wingbot_tick.h"
#include "wingbot_usart.h"

#if !(defined null_ptr)
#define null_ptr (void *)0
#endif

#define BTN_FR_TIMEOUT_MAX 100U

class Stream
{
public:
    USART_INFO* info;
    ARM_DRIVER_USART* driver;

public:
    Stream(USART_INFO* info, ARM_DRIVER_USART* driver);
    void flush(void){;}
    void clear_rx_buf(void);
    bool begin(int baudrate);
    bool begin(int baudrate, unsigned int format)
    {
        begin(baudrate);
    }
    void write(uint8_t data);
    void writeLine(const char* p);
    void writeBytes(u8* p, u16 len);
    uint8_t read(void);
    uint8_t available(void);
    uint16_t readLine(unsigned char* pbuf);
    uint16_t readBytes(uint8_t* buf_in, uint16_t len);
    uint16_t readAll(uint8_t* buf_in);
    void writeString(const char* msg);
    bool dataReady(){return this->info->trans_info.rx_dataReady;}
};

void bitWrite(uint16_t &data, uint8_t n, bool b);

#endif
/* end of file */

